package kvoog.arkanoid.screens;

import kvoog.arkanoid.core.KvoogGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

public class KvoogScreen implements Screen {

	protected KvoogGame game;
	protected final Stage stage;
	
	private Skin skin;
	private Table table;
	private SpriteBatch spriteBatch;
	
	public KvoogScreen(KvoogGame game) {
		this.game = game;
		this.stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
	}
	
	protected Skin getSkin() {
		if (skin == null) {
			skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
		}
		return skin;
	}
	
	protected Table getTable() {
		if (table == null) {
			table = new Table(getSkin());
			table.setFillParent(true);
			stage.addActor(table);
		}
		return table;
	}
	
	public SpriteBatch getSpriteBatch() {
		if (spriteBatch == null) {
			spriteBatch = new SpriteBatch();
		}
		return spriteBatch;
	}

	@Override
	public void render(float delta) {
		stage.act(delta);	
		
		GLCommon gl = Gdx.graphics.getGLCommon();
		gl.glClearColor(0, 0, 0, 0);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.draw();
	}

	@Override
	public void resize(int width, int height) {

	}

	@Override
	public void show() {
		
	}

	@Override
	public void hide() {

	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {
		if (skin != null) {
			skin.dispose();
		}
		if (stage != null) {
			stage.dispose();
		}
		if (spriteBatch != null) {
			spriteBatch.dispose();
		}
	}

}
